{include file="/public/header"}
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding-top: 40px;">
            <!-- 分布表单开始 -->
            <div class="layui-tab layui-steps layui-steps-readonly" lay-filter="formStepsStep"
                 style="max-width: 650px;">
                <!-- 标题 -->
                <ul class="layui-tab-title">
                    <li class="layui-this">
                        <i class="layui-icon layui-icon-ok">1</i>
                        <span class="layui-steps-title">第一步</span>
                        <span class="layui-steps-content">填写卡密内容</span>
                    </li>
                    <li>
                        <i class="layui-icon layui-icon-ok">2</i>
                        <span class="layui-steps-title">第二步</span>
                        <span class="layui-steps-content">填写兑换信息</span>
                    </li>
                    <li>
                        <i class="layui-icon layui-icon-ok">3</i>
                        <span class="layui-steps-title">第三步</span>
                        <span class="layui-steps-content">兑换成功</span>
                    </li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <!-- 表单一 -->
                        <form class="layui-form" style="max-width: 460px;margin: 0 auto;padding: 40px 30px 0 0;">
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label layui-form-required">卡密:</label>
                                <div class="layui-input-block">
                                    <input name="cdkey" placeholder="请输入卡密内容" value="" class="layui-input"
                                           lay-verType="tips" lay-verify="required" required/>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="button" class="layui-btn" lay-filter="formStepSubmit1" lay-submit>&emsp;下一步&emsp;
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <!-- 表单二 -->
                        <form class="layui-form" style="max-width: 460px;margin: 0 auto;padding: 40px 30px 0 0;">
                            <div id="SF_Info_Input"></div>

                                <div style="text-align: center;">
                                    <button type="button" class="layui-btn layui-btn-primary" data-steps="prev"> 上 一 步&nbsp;
                                    </button>
                                    <button class="layui-btn" lay-filter="formStepSubmit2" lay-submit>&emsp;提交&emsp;
                                    </button>
                                </div>

                        </form>
                    </div>
                    <div class="layui-tab-item text-center" style="padding-top: 40px;">
                        <!-- 表单三 -->
                        <i class="layui-icon layui-icon-ok layui-circle"
                           style="background: #52C41A;color: #fff;font-size:30px;font-weight:bold;padding: 20px;line-height: 80px;"></i>
                        <div style="font-size: 24px;color: #333;margin-top: 30px;">兑换成功</div>
                        <div style="font-size: 14px;color: #666;margin-top: 20px;">兑换奖励已到账</div>
                        <div style="text-align: center;margin: 50px 0 25px 0;">
                            <button class="layui-btn" lay-filter="formStepSubmit3" lay-submit>继续兑换</button>
                            <button class="layui-btn layui-btn-primary">查看记录</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item formBasForm">
                <div class="sf-tips">
                    {$cdkey_notice|default='暂无公告'}
                </div>
            </div>
            <!-- //分布表单结束 -->
        </div>
    </div>
</div>
<script type="text/html" id="SF_Auth">
    <form class="layui-form" lay-filter="SF_Auth">
        <input type="hidden" name="cdkey">
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">授权内容:</label>
            <div class="layui-input-block">
                <input type="text" name="auth_info" placeholder="请输入授权内容"
                       class="layui-input" lay-verType="tips" lay-verify="required" required>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label layui-form-required">授权者QQ:</label>
            <div class="layui-input-block">
                <input type="number" name="qq" placeholder="请输入授权者QQ" class="layui-input"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
    </form>
</script>
{include file="/public/footer"}
<script>
    layui.use(['layer', 'form', 'steps', 'notice'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var steps = layui.steps;
        var notice = layui.notice;

        /* 表单一提交事件 */
        form.on('submit(formStepSubmit1)', function (res) {
            notice.msg('正在执行中..', {icon: 4, close: true});
            $.ajax({
                type: "POST",
                url: '{:url("/Cdkey/exchange")}',
                data: res.field,
                dataType: "json",
                success: function(data) {
                    notice.destroy();
                    if (data.code == 0) {
                        notice.msg(data.msg, {icon: 1, audio:'1'});
                        if(data.data == 'auth'){
                            $("#SF_Info_Input").html($("#SF_Auth").html());
                            steps.next('formStepsStep');
                        }else{
                            steps.go('formStepsStep',2);
                        }
                    }else{
                        notice.msg(data.msg, {icon: 2, audio:'1'});
                    }
                },
                error: function() {
                    notice.destroy();
                    notice.msg("服务器错误！", {icon: 2, audio:'1'});
                }
            });
            return false;
        });

        /* 表单二提交事件 */
        form.on('submit(formStepSubmit2)', function (data) {
            data.field.step = 1;
            data.field.cdkey_type = 'auth';
            data.field.cdkey = $("input[name='cdkey']").val();
            notice.msg('正在执行中..', {icon: 4, close: true});
            $.ajax({
                type: "POST",
                url: '{:url("/Cdkey/exchange")}',
                data: data.field,
                dataType: "json",
                success: function(data) {
                    notice.destroy();
                    if (data.code == 0) {
                        notice.msg(data.msg, {icon: 1, audio:'1'});
                        steps.next('formStepsStep');
                    }else{
                        notice.msg(data.msg, {icon: 2, audio:'1'});
                    }
                },
                error: function() {
                    notice.destroy();
                    notice.msg("服务器错误！", {icon: 2, audio:'1'});
                }
            });
            return false;
        });

        form.on('submit(formStepSubmit3)', function (data) {
            $("input[name='cdkey']").val('');
            steps.next('formStepsStep');
            return false;
        });

    });
</script>